<%--
  Created by IntelliJ IDEA.
  User: 金贤哲
  Date: 2017/5/2 0002
  Time: 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>Title</title>
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" href="${ctxStatic}/layui/css/layui.css"   />
    <script src="${ctxStatic}/js/widget/stickytableheaders/js/jquery.stickytableheaders.min.js"></script>
    <script src="${ctxStatic}/layui/layui.js"></script>
    <script>
        layui.use('element', function(){
            var element = layui.element();

            //一些事件监听
            element.on('tab(demo)', function(data){
                console.log(data);
            });
        });
    </script>
    <script src="${ctxStatic}/layer/layer.js"></script>

</head>

<body>
<div class="layui-tab" lay-filter="test">
    <input type="hidden" id="memberId" value="${member.id}">
    <ul class="layui-tab-title">
        <li class="layui-this"  lay-id="11">服务记录<span style="color: #9a161a">[${fnc:getServiceNum(member.id)}条]</span></li>
        <shiro:hasPermission name="sys:businessrecord:tBusinessRecord:view">
        <li  lay-id="22">商务谈单记录<span style="color: #9a161a">[${fnc:getBusinessNum(member.id)}条]</span></li></shiro:hasPermission>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">

            <div class="row" style="text-align: center;"><h2>【<c:if test="${member.realname != null}">${member.realname}</c:if><c:if test="${member.realname == null}">${member.nickname}</c:if>】的服务记录</h2></div>
            <div class="row" style="text-align: center;padding-top: 11px;">
                <div class="col-md-2 col-md-offset-5" style="text-align: center;font-size:32px;overflow: hidden; ">
                    服务记录：<input id="record" type="text" style="width: 60%;height: 30px;"  class="input-xlarge required" />
                    <%--<shiro:hasPermission name="sys:member:member:sr:edit">--%>
                    <input id="btnAdd" class="btn btn-danger" type="button" value="添加" />
                    <%--</shiro:hasPermission>--%>
                </div>
            </div>
            <div class="row" style="padding-left: 20px">
                <table id="contentTable1" class="table table-striped table-bordered table-condensed">
                    <thead>
                    <tr>
                        <th style="width: 1%">序号</th>
                        <th style="width: 10%">记录时间</th>
                        <th style="width: 10%">记录人</th>
                        <th style="width: 70%">服务记录</th>
                        <shiro:hasPermission name="sys:member:member:sr:edit">
                            <th style="width: 2%">操作</th>
                        </shiro:hasPermission>
                    </tr>
                    </thead>
                    <tbody>
                    <c:choose>
                        <c:when test="${empty serviceRecords || fn:length(serviceRecords)==0 }">	<tr> <td colspan="5"><div class="col-md-2 col-md-offset-5" style="text-align: center;font-size:32px; line-height:550px; height: 550px;">暂无对该用户的服务记录 </div></td> </tr></c:when>
                        <c:otherwise>
                            <c:forEach items="${serviceRecords}" var="sr" varStatus="p">
                                <tr>
                                    <td>${p.index+1}</td>
                                    <td>
                                        <fmt:formatDate value="${sr.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                    </td>
                                    <td>${sr.createBy.name}</td>
                                    <td>
                                            ${sr.record}
                                    </td>
                                    <shiro:hasPermission name="sys:member:member:sr:edit">
                                        <td>
                                            <a href="#" class="btn-add" data-id="${sr.id}">删除</a>
                                        </td>
                                    </shiro:hasPermission>
                                </tr>
                            </c:forEach>
                        </c:otherwise>
                    </c:choose>
                    <c:forEach items="${page.list}" var="loan">

                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
        <shiro:hasPermission name="sys:businessrecord:tBusinessRecord:view">
            <div class="layui-tab-item">
                <div class="row" style="text-align: center;"><h2>【<c:if test="${member.realname != null}">${member.realname}</c:if><c:if test="${member.realname == null}">${member.nickname}</c:if>】的商务谈单记录</h2></div>
                <div class="row" style="text-align: center;padding-top: 11px;">
                    <div class="col-md-2 col-md-offset-5" style="text-align: center;font-size:32px;overflow: hidden; ">
                        谈单记录：<input id="record1" type="text" style="width: 60%;height: 30px;"  class="input-xlarge required" />
                        <%--<shiro:hasPermission name="sys:member:member:sr:edit">--%>
                        <input id="btnAdd1" class="btn btn-danger" type="button" value="添加" />
                        <%--</shiro:hasPermission>--%>
                    </div>
                </div>
                <div class="row" style="padding-left: 20px">
                    <table id="contentTable" class="table table-striped table-bordered table-condensed">
                        <thead>
                        <tr>
                            <th style="width: 1%">序号</th>
                            <th style="width: 10%">记录时间</th>
                            <th style="width: 10%">记录人</th>
                            <th style="width: 70%">服务记录</th>
                            <shiro:hasPermission name="sys:businessrecord:tBusinessRecord:edit">
                                <th style="width: 2%">操作</th>
                            </shiro:hasPermission>
                        </tr>
                        </thead>
                        <tbody>
                        <c:choose>
                            <c:when test="${empty tBusinessRecords || fn:length(tBusinessRecords)==0 }">	<tr> <td colspan="5"><div class="col-md-2 col-md-offset-5" style="text-align: center;font-size:32px; line-height:550px; height: 550px;">该用户暂无商务谈单记录 </div></td> </tr></c:when>
                            <c:otherwise>
                                <c:forEach items="${tBusinessRecords}" var="sr1" varStatus="p">
                                    <tr>
                                        <td>${p.index+1}</td>
                                        <td>
                                            <fmt:formatDate value="${sr1.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td>${sr1.createBy.name}</td>
                                        <td>
                                                ${sr1.record}
                                        </td>
                                        <shiro:hasPermission name="sys:businessrecord:tBusinessRecord:edit">
                                            <td>
                                                <a href="#" class="btn-add1" data-id="${sr1.id}">删除</a>
                                            </td>
                                        </shiro:hasPermission>
                                    </tr>
                                </c:forEach>
                            </c:otherwise>
                        </c:choose>
                        <c:forEach items="${page.list}" var="loan">

                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </shiro:hasPermission>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#btnAdd").click(function(){
            var memberId=$("#memberId").val();
            var record=$("#record").val();
            if(!record){
                layer.alert("请输入服务记录",{offset:'150px'},-1);
                return;
            }
            var load = layer.load(2, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                type : "POST",  //提交方式
                url : "${ctx}/sys/servicerecord/serviceRecord/ajaxSave",//路径
                data : {"member.id":memberId,"record":record},//数据，这里使用的是Json格式进行传输
                success : function(data) {//返回数据根据结果进行相应的处理
                    if(data){
                        layer.msg("操作成功",{offset:'150px'},function(){
                            setTimeout(function () {
                                window.location.reload();
                            },1500)
                        });
                    }else{
                        layer.msg("操作失败,检查记录是否存在！",{offset:'150px'},function() {
                            setTimeout(function () {
                                window.location.reload();
                            }, 1500)
                        });
                    }
                    //    layer.close(load);
                }
            });
        });

        $("#contentTable").stickyTableHeaders();
        $("#contentTable1").stickyTableHeaders();
        $(".btn-add").click(function(){
            var id=$(this).data("id");
            if(!id){
                layer.msg("删除失败，请联系管理员",{time:500},-1);
                return;
            }
            layer.confirm('确认要删除吗？', {
                btn: ['确认','取消'], //按钮
                offset:'150px',
                shade: false //不显示遮罩
            }, function(index){
                $.ajax({
                    type : "POST",  //提交方式
                    url : "${ctx}/sys/servicerecord/serviceRecord/ajaxDelete",//路径
                    data : {"id":id},//数据，这里使用的是Json格式进行传输
                    success : function(data) {//返回数据根据结果进行相应的处理
                        if(data){
                            layer.msg("操作成功,",{offset:'150px'},function(){
                                setTimeout(function () {
                                    window.location.reload();
                                },1000)
                            });
                        }else{
                            layer.msg("操作失败",{offset:'150px'},function(){
                                setTimeout(function () {
                                    window.location.reload();
                                },1000)
                            });
                        }
                    }
                });
            });


        });
        $("#btnAdd1").click(function(){
            var memberId=$("#memberId").val();
            var record=$("#record1").val();
            if(!record){
                layer.alert("请输入谈单记录",-1);
                return;
            }
            var load = layer.load(2, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            // document.getElementById("btnAdd1").style.display = "none";
            $.ajax({
                type : "POST",  //提交方式
                url : "${ctx}/sys/businessrecord/tBusinessRecord/ajaxSave",//路径
                data : {"member.id":memberId,"record":record},//数据，这里使用的是Json格式进行传输
                success : function(data) {//返回数据根据结果进行相应的处理
                    if(data){
                        layer.msg("操作成功",{offset:'150px'},function(){
                            setTimeout(function () {
                                window.location.reload(true);
                            },2000)
                        });
                    }else{
                        layer.msg("操作失败,检查记录是否存在！",{offset:'150px'},function() {
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000)
                        });
                    }
                }
            });
        });
        $(".btn-add1").click(function(){
            var id=$(this).data("id");
            if(!id){
                layer.msg("删除失败，请联系管理员",{time:500},-1);
                return;
            }
            layer.confirm('确认要删除吗？', {
                btn: ['确认','取消'], //按钮
                shade: false //不显示遮罩
            }, function(index){
                $.ajax({
                    type : "POST",  //提交方式
                    url : "${ctx}/sys/businessrecord/tBusinessRecord/ajaxDelete",//路径
                    data : {"id":id},//数据，这里使用的是Json格式进行传输
                    success : function(data) {//返回数据根据结果进行相应的处理
                        if(data){
                            layer.msg("操作成功,",{time:500},function(){
                                setTimeout(function () {
                                    window.location.reload();
                                },2000)
                            });
                        }else{
                            layer.alert("操作失败",{time:500},-1);
                        }
                    }
                });
            });


        });


    });

    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块
        //Hash地址的定位
        var layid = location.hash.replace(/^#test=/, '');

        element.tabChange('test', layid);

        element.on('tab(demo)', function(elem){
            location.hash = 'test='+ $(this).attr('lay-id');
            alert(layid);
        });

    });
</script>
</body>

</html>
